<template>
  <div class="houseList">
    <!-- <ad unit-id="adunit-ee3afece45663dd6" ad-type="video" ad-theme="white"></ad> -->
    <!-- <hunk-head name="马上安家"></hunk-head> -->
    <!-- <div class="search">
      <input type="text" placeholder="请输入地址、门牌号">
    </div>
    <div class="type-list">
      <div v-for="(item,index) in btnList" :key="index" :class="['item', item.color]" @click="clickBtn(item)">
        {{item.text}}
      </div>
    </div>
    <div class="home-list">
      <div class="home-item">
        <div class="home-name">江苏省南京市雨花台区软件谷人才公寓</div>
        <div class="item-list">
          <div :class="['one', typeList[0].bgcolor]" @click="clickItem()">
            <div class="top" style="width:60px">
              <img v-if="typeList[0].img" :src="typeList[0].img" />
            </div>
            <div class="miaoshu">自持-6栋二单元304室</div>
            <div class="yuezu">
              <span>2738</span>
              /月
            </div>
            <div class="type type1">
              <img :src="typeList[0].type" alt="" srcset="">
            </div>
          </div>
          <div :class="['one', typeList[1].bgcolor]">
            <div class="top" style="width:70px">
              <img v-if="typeList[1].img" :src="typeList[1].img" />
            </div>
            <div class="miaoshu">自持-6栋二单元304室</div>
            <div class="yuezu">
              <span>2738</span>
              /月
            </div>
            <div class="type type2">
              <img :src="typeList[1].type" alt="" srcset="">
            </div>
          </div>
          <div :class="['one', typeList[2].bgcolor]">
            <div class="top">
              <img v-if="typeList[2].img" :src="typeList[2].img" />
            </div>
            <div class="miaoshu">自持-6栋二单元304室</div>
            <div class="yuezu">
              <span>2738</span>
              /月
            </div>
            <div class="type type3">
              <img :src="typeList[2].type" alt="" srcset="">
            </div>
          </div>
          <div :class="['one', typeList[0].bgcolor]">
            <div class="top" style="width:60px">
              <img v-if="typeList[0].img" :src="typeList[0].img" />
            </div>
            <div class="miaoshu">自持-6栋二单元304室</div>
            <div class="yuezu">
              <span>2738</span>
              /月
            </div>
            <div class="type type1">
              <img :src="typeList[0].type" alt="" srcset="">
            </div>
          </div>
          <div :class="['one', typeList[1].bgcolor]">
            <div class="top" style="width:70px">
              <img v-if="typeList[1].img" :src="typeList[1].img" />
            </div>
            <div class="miaoshu">自持-6栋二单元304室</div>
            <div class="yuezu">
              <span>2738</span>
              /月
            </div>
            <div class="type type2">
              <img :src="typeList[1].type" alt="" srcset="">
            </div>
          </div>
          <div :class="['one', typeList[2].bgcolor]">
            <div class="top">
              <img v-if="typeList[2].img" :src="typeList[2].img" />
            </div>
            <div class="miaoshu">自持-6栋二单元304室</div>
            <div class="yuezu">
              <span>2738</span>
              /月
            </div>
            <div class="type type3">
              <img :src="typeList[2].type" alt="" srcset="">
            </div>
          </div>
        </div>
        
      </div>
      
    </div> -->
    <div class="content">
      <hunk-list class="flex1" :list="houseList" @clickitem="clickitem" @clickBtn="clickBtn" @searchInput= "searchInput" @onRefresh="onRefresh"></hunk-list>
    </div>
  </div>
</template>

<script>
import Head from '@componentsMine/head'
import List from '@componentsMine/list'
import { getHouseList } from '@/apis/housesInfo'
export default {
  components: {
    'hunk-head': Head,
    'hunk-list': List
  },
  data() {
    return {
      interstitialAd:null,
      addresslike: '',  //模糊查询
      houseattribute: [],  // 出租方式 0-自持 1-托管
      housetype: [],  // 0-空 1-已租 2-欠租 3-接近交租 4-租约快到期 5-未绑定门锁
      outtype: [],  //出租方式 0-合租 1-整租
      houseList: [
      ]
    }
  },
 
  created(){
    this.getHouseList()
    if (this.$store.state.baseStore.userInfo.usertype == 1) { 
      if(wx.createInterstitialAd){
        this.interstitialAd = wx.createInterstitialAd({ adUnitId: 'adunit-b7624e2779b6167a' })
        this.interstitialAd.onLoad(() => {
          console.log('onLoad event emit')
        })
        this.interstitialAd.onError((err) => {
          console.log('onError event emit', err)
        })
        this.interstitialAd.onClose((res) => {
          console.log('onClose event emit', res)
        })
      }
      this.interstitialAd.show().then().catch(err => {
        console.log(err)
      })
    }
  },
  onShow(){
    this.getHouseList()
  },
  computed: {
    userid(){
      return this.$store.state.baseStore.userInfo.userid
    },
  },
  methods: {
    onRefresh(){
      this.getHouseList()
    },
    clickitem(item){
      let data = {
        houseid:item.houseid
      }
      this.$jump({ path: '/pages/manage/houseList/commponents/detail?query='+ JSON.stringify(data) })
    },
    getHouseList(){
      const data = {
        addresslike: this.addresslike,  //模糊查询
        houseattribute: this.houseattribute,  // 出租方式 0-自持 1-托管
        housetype: this.housetype,  // 0-空 1-已租 2-欠租 3-接近交租 4-租约快到期 5-未绑定门锁
        outtype: this.outtype,   //出租方式 0-合租 1-整租
        userid: this.userid
      }
      getHouseList(data).then(res=>{
        if(res.code == 200){
          if(!res.data){
            this.houseList = []
            return
          }
          this.houseList = res.data
        }
      })
    },
    clickBtn(item){
      let arr = item.split(',')
      this[arr[0]] = arr
      this[arr[0]].shift()
      this.getHouseList()
    },
    searchInput(item){
      this.addresslike = item
      this.getHouseList()
    }
  },
  mounted() {
  }
}
</script>

<style lang="scss" scoped>
.houseList{
  width: 100vw;
  box-sizing: border-box;
  height: 100%;
  background: #F9F9F9;
  display: flex;
  flex-direction: column;
  .content{
    flex: 1;
    overflow-y: auto;
    display: flex;
  }
  .flex1{
    flex: 1;
    display: flex;
  }
}
</style>
